
<!--
    查看医生管理页面
    温世杰
 -->
 <template>
  <div>
    <div style="margin: 10px 0">
      <el-input
        v-model="sousuofrom.doctorName"
        style="width: 200px"
        placeholder="请输入昵称"
        suffix-icon="el-icon-message"
        class="ml-5"
      ></el-input>
      <el-button @click="load()" class="ml-5" type="primary">搜索</el-button>
      <el-button @click="reset()" style="margin-left: 5px" type="warning"
        >重置</el-button
      >
    </div>
    <!-- 表格数据 -->
    <el-table :data="tableData" border stripe header-cell-class-name="headerBg">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="ID" width="50" />
      <el-table-column prop="doctorSex" label="性别" width="120">
        <template slot-scope="scope">
          {{
            scope.row.doctorSex == 0
              ? "男"
              : scope.row.doctorSex == 1
              ? "女"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column prop="doctorAge" label="年龄" width="160" />
      <el-table-column prop="doctorName" label="医生姓名" width="160" />
      <el-table-column prop="title" label="职称" width="160" />
      <el-table-column prop="address" label="地址" width="160" />
      <el-table-column prop="job" label="是否在职" width="160">
        <template slot-scope="scope">
          {{ scope.row.job == 1 ? "在职" : scope.row.job == 2 ? "离职" : "" }}
        </template>
      </el-table-column>
      <el-table-column prop="hospital" label="所属医院" width="160" />
      <el-table-column prop="department" label="科室" width="160" />
      <el-table-column prop="physicianNumber" label="医师证号" width="160" />
      <el-table-column prop="life" label="从业年限" width="160" />
      <el-table-column
        prop="identityNumber"
        label="身份证号"
        width="160"
      ></el-table-column>
      <el-table-column
        prop="phoneNumber"
        label="手机号"
        width="160"
      ></el-table-column>
      <el-table-column prop="personalPhotos" label="医生个人照片" width="120">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="
             $imageUrl +
              scope.row.personalPhotos
            "
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="certificatePhoto" label="职业证书" width="120">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="
             $imageUrl +
              scope.row.certificatePhoto
            "
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="warning" @click="deldactor(scope.row.id)"
            >恢复<i class="el-icon-edit"></i
          ></el-button>
          <el-button type="warning" @click="docaorDelete(scope.row.id)"
            >删除<i class="el-icon-edit"></i
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div style="padding: 10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        style="margin-top: 20px"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
// import  request  from '@/utils/request.js'

export default {
  data() {
    return {
      currentPage4: 1, // 第几页
      // 表格数据
      tableData: [],
      // multipleSelection:[],
      pageNum: 1, // 一条一条的走 条数
      pageSize: 5, // 一页五条页数
      total: 0,
      avatarUrl: "",
      // 模糊查搜索框数值
      sousuofrom: {
        doctorName: "",
      },
      rules: {
        nickname: [
          { required: true, message: "请输入昵称", trigger: "blur" },
          { min: 1, max: 6, message: "长度在 1 到 6个字符", trigger: "blur" },
        ],
      },
    }; // return
  },
  mounted() {
    this.load();
  },
  // 方法集合
  methods: {
    load() {
      // 通过名称查询注销用户信息
      this.$axios
        .get("/physician/doctorLogOff", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            doctorName: this.sousuofrom.doctorName,
          },
        })
        .then((res) => {
          this.tableData = res.data.data.content;
          this.total = res.data.data.totalSize;
        })
        .catch((err) => {
        });
    },

    // 彻底删除注销的用户
    deldactor(id) {
      //
      this.$confirm("此操作会恢复注销的用户, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .delete("/physician/doctorRestore", {
              params: {
                id: id,
              },
            })
            .then((res) => {
              if (res.data.code === 200) {
                this.myMessage("success", "恢复成功");
                this.load();
              } else {
                this.myMessage("warning", "恢复失败");
              }
            })
            .catch((res) => {
              this.myMessage("error", "恢复失败");
            });
        })
        .catch((res) => {
          this.myMessage("info", "已取消恢复");
        });
    },

    // 彻底删除注销的用户
    docaorDelete(id) {
      //
      this.$confirm("此操作将注销用户彻底删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .delete("/physician/doctorRestoreDelete", {
              params: {
                id: id,
              },
            })
            .then((res) => {
              if (res.data.code === 200) {
                this.myMessage("success", "删除成功");
                this.load();
              } else {
                this.myMessage("warning", "删除失败");
              }
            })
            .catch((res) => {
              this.myMessage("error", "删除失败，请联系管理员");
            });
        })
        .catch((res) => {
          this.myMessage("info", "已取消删除");
        });
    },
    myMessage(type, message) {
      this.$message({
        message: message,
        type: type,
      });
    },
    logoff(row) {
      // 用户禁言
      this.$axios
        .post("/user/updateSilencedState/", row)
        .then((res) => {
          if (res.data.code === 200) {
            this.$message.success("状态已修改");
            // 重新渲染刷新表格
            this.load();
          }
        });
    },
    handleSizeChange(val) {
      // 改变每页条数
      this.pageSize = val;
      this.load();
    },
    handleCurrentChange(val) {
      // 改变当前页
      this.pageNum = val;
      this.load();
    },
  },
};
</script>

<style scoped>
html,
body,
div {
  margin: 0;
  padding: 0;
  text-align: left;
}
html.body {
  height: 100%;
}
/* *{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
} */
.ml-5 {
  margin-left: 5px;
}
.mr-5 {
  margin-right: 5px;
}
.pd-10 {
  padding: 10px 0;
}
</style>
